var app = getApp();
var ApiUrl = app.globalData.ApiUrl;
var mph = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    num:0,
    my_regiment_btn:[
      {
        name:'quanbu',
        text:'全部'
      },{
        name: 'pingtuanzhong',
        text: '拼团中'
      }, {
        name: 'pingtuanchengong',
        text: '拼团成功'
      }, {
        name: 'pingtuanshixiao',
        text: '拼团失效'
      }
    ],
    my_regiment_list:[],
    spell_list:[],
    my_regiment_data:[
    ]
  },
  go_pt_front_page(){
    wx.redirectTo({
      url: "/pages/pt_front_page/pt_front_page"
    })
  },
  go_my_regiment() {
    // wx.navigateTo({
    //   url: "/pages/my_regiment/my_regiment"
    // })
  },
  active_btn(e){
    let that = this;
    let ind = e.currentTarget.dataset.index;
    that.data.num = ind;

    that.setData({
      num: that.data.num
    });
    that.spell_list(that.data.num);
  },
  //index.php?act=other_spell&op=spell_list
  //我的拼团信息,我参与的和我开团的拼团都在列表中,每页获取15条
  spell_list(n){
    var that = this;
    var key = wx.getStorageSync('key');
    var url = '/index.php?act=other_spell&op=spell_list';
    mph.postRequest(url, {
      act: 'other_spell',
      op: 'spell_list',
      key: key,
      state:n,
      page:1,
    },
      function (res) {
        that.data.my_regiment_list = [];
        let reslist = res.data.datas;
        // console.log('我的拼团信息:======>',reslist);
        if (res.data.code == 200) {
          that.data.my_regiment_list = reslist;
          that.setData({
            my_regiment_list: that.data.my_regiment_list
          })
        }
      })
  },
  go_group_details(e){
    let psn = e.currentTarget.dataset.psn;
    let cont = e.currentTarget.dataset.item;
    wx.setStorageSync('ptcont', cont);

    wx.navigateTo({
      url: "/pages/group_details/group_details?psn=" + psn + '&goods_id=' + cont.goods_id
    })
  },
  go_order(e) {///pages/order/order?goodsId={{spell_list.goods_id}}&buynum=1&type=only"
    let goodsId = e.currentTarget.dataset.goods_id;
    wx.navigateTo({
      url: "/pages/order/order?goodsId=" + goodsId+"&buynum=1&type=only"
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.spell_list('0');
  },
})